package com.xqq.lottery.util;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Util {
	
	/**
	 * 将int数值转换成四个字节的byte数组,本方法适用于（高位在前，低位在后）的顺序。
	 * @param value
	 * @return
	 */
	public static byte[] intToBytes(int value){
		byte [] src =new byte[4];
		src[0] = (byte)((value >> 24) & 0xFF);
		src[1] = (byte)((value >> 16) & 0xFF);
		src[2] = (byte)((value >> 8)  & 0xFF);
		src[3] = (byte)(value & 0xFF);
		return src;
	}
	
	/**
	 * byte数组中取int值,本方法适用于(低位在后，高位在前)
	 * @param src
	 * @param offset
	 */
	public static int bytesToInt(byte[] src,int offset){
		  int value;    
		   value = (int) ( ((src[offset] & 0xFF)<<24)  
		            |((src[offset+1] & 0xFF)<<16)  
		            |((src[offset+2] & 0xFF)<<8)  
		            |(src[offset+3] & 0xFF));  
		    return value;
	}


}
